#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <bmpfile.h>

int
main(int argc, char **argv)
{
	rgb_pixel_t r = { .blue = 0, .green = 0, .red = 255, .alpha = 255 },
		    g = { .blue = 0, .green = 255, .red = 0, .alpha = 255 },
		    b = { .blue = 255, .green = 0, .red = 0, .alpha = 255 },
		    y = { .blue = 0, .green = 255, .red = 255, .alpha = 255 };
	bmpfile_t *bmp;
	register int i, j;

	if (bmp = bmp_create(640, 480, 32), bmp == NULL) {
		printf("bmp_create() failed\n");
		return 1;
	}

	for (i = 0; i < 640 / 2; i++) {
		if (i & 1) {
			j = 0;
			while (j < 480) {
				bmp_set_pixel(bmp, i, j, g);
				bmp_set_pixel(bmp, i, j + 1, b);
				j += 2;
			}
		} else {
			j = 0;
			while (j < 480) {
				bmp_set_pixel(bmp, i, j, r);
				bmp_set_pixel(bmp, i, j + 1, y);
				j += 2;
			}
		}
	}
	while (i < 640) {
		rgb_pixel_t avg = { .blue = 0xbf, .green = 0xff, .red = 0x7f, .alpha = 255 };
		for (j = 0; j < 480; j++)
			bmp_set_pixel(bmp, i, j, avg);
		i++;
	}
	bmp_set_pixel(bmp, 10, 240, b);
	bmp_set_pixel(bmp, 11, 240, r);

	bmp_save(bmp, argc >= 2 ? argv[1] : "out.bmp");
	bmp_destroy(bmp);

	return 0;
}
